package components.utils
{
	public class StringUtil
	{
		public static function isEmpty(str:String):Boolean
		{
			return str=="" || str==null;
		}
		
		/**
		 *替换字符串 
		 * @param str
		 * @param res
		 * @return 
		 * 
		 */		
		public static  function formatString(str:String, ...res):String
		{
			if(str==null)
				return ""; 
			
			for(var i:uint=0;i<res.length;i++)
			{
				str=str.replace(new RegExp("\\{"+i+"\\}", "g"),res[i]);
			}
			return str;
		}
		
		public static function insertStr(str:String,index:int,insertStr:String):String
		{
			var strList:Array=str.split("");
			strList.splice(index,0,insertStr);
			return strList.join("");
		}
		
		public static function removeStr(str:String,index:int,length:int):Object
		{
			if(index<0)
				return str;
			
			var strList:Array=str.split("");
			var removeStr:String=strList.splice(index,length);
			return {str:strList.join(""),removeStr:removeStr};
		}
	}
}